'''
Created on Sep 5, 2009

@author: echeek & klewi <3
'''



def nextFraction(a, b):
    return (a[0]+b[0], a[1]+b[1]);

def valueOfFraction(a):
    return float(a[0])/float(a[1]);

def compareTo(a, b):
    a=valueOfFraction(a);
    b=valueOfFraction(b);
    if a==b:
        return 0;
    if a<b:
        return -1;
    return 1;    
    
def Euler71():
    target=(3,7);#(3,7);
    seq=[(0,1), (1,2), (1,1)];
    limit=10**6;
    
    beg=seq[0];
    mid=seq[1];
    end=seq[2];
    
    skip=False;
    
    for i in range(limit-1): #range(10**6-1):
        row = i + 3;
        if(beg[1]>row or mid[1]>row):
            continue;
        
        #print beg;   
        #print mid; 
        #print end;    
        #print "";
        order=compareTo(target,mid );
        
        if(order<=0):
            end=mid;
            
        if(order>0):
            beg=mid;
 
        mid=nextFraction(beg, end);
        #print "mid: " + str(mid) + " row: " + str(row);


    print beg;        



Euler71();